<?php

declare(strict_types=1);
/**
 * This file is part of MineAdmin.
 *
 * @link     https://www.mineadmin.com
 * @document https://doc.mineadmin.com
 * @contact  root@imoi.cn
 * @license  https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
 */

namespace App\Repository;

use App\Model\Homework;
use App\Repository\IRepository;
use Hyperf\Collection\Arr;
use Hyperf\Database\Model\Builder;

/**
 * Class HomeworkRepository.
 * @extends IRepository<Homework>
 */
final class HomeworkRepository extends IRepository
{
    public function __construct(protected readonly Homework $model) {}
    public function handleSearch(Builder $query, array $params): Builder
    {
        return $query
            ->with([
                'creator',
            ])
            ->when(
                Arr::get($params, 'name'),
                static function (Builder $query, $name) {
                    $query->where('name', 'like', '%' . $name . '%');
                }
            );
    }
}
